package com.scau.hwadee.examination.controller;

import com.scau.hwadee.examination.entity.Graduaterequirment;
import com.scau.hwadee.examination.service.GraduaterequirmentService;
import com.scau.hwadee.examination.utils.JsonUtils;
import com.scau.hwadee.examination.vo.ResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: wrh
 * @Date: 2019/8/2 15:49
 */
@Slf4j
@Controller
@RequestMapping("/Graduaterequirment")
@Api(tags ="Graduaterequirment" ,description = "专业毕业条件管理")
public class GraduaterequirmentController {
    @Autowired
    private GraduaterequirmentService graduaterequirmentService;

    @PutMapping(value = "/graduaterequirment")
    @ApiOperation(value ="修改毕业条件")
    public ResponseEntity<ResponseVo> updateGraduaterequirment(@RequestBody Graduaterequirment graduaterequirment){
     ResponseVo vo=ResponseVo.instance();
        int cnt=graduaterequirmentService.updateGraduaterequirement(graduaterequirment);
        if(cnt>0)
            vo.setMessage("修改成功");
        else vo.setMessage("修改失败");
     return new ResponseEntity<>(vo, HttpStatus.OK);
    }

    @GetMapping(value = "/graduaterequirment")
    @ApiOperation(value = "查找专业毕业条件" )
    public ResponseEntity<ResponseVo> getGraduaterequirmentByMajor(@RequestParam("mjId") String mjId){
        ResponseVo vo=ResponseVo.instance();
        vo.setData(graduaterequirmentService.getByMajor(mjId));
        return new ResponseEntity<>(vo, HttpStatus.OK);
    }

    @PostMapping("/graduaterequirment")
    @ApiOperation(value = "增加专业毕业条件")
    public ResponseEntity<ResponseVo> addGraduaterequirment(@RequestBody String params){
        ResponseVo vo=ResponseVo.instance();
        Graduaterequirment graduaterequirment=JsonUtils.JSONToObject(params,Graduaterequirment.class);
        int cnt=graduaterequirmentService.addGraduaterequirement(graduaterequirment);
        if(cnt>0)
            vo.setMessage("添加成功");
        else vo.setMessage("添加失败");
        return new ResponseEntity<>(vo, HttpStatus.OK);
    }

}
